#include <bits/stdc++.h>
using namespace std;
#define N 1005
typedef struct Node
{
    char val;
    int left, right;
}Node;
Node node[N];
int p = 1;
char midStr[10], postStr[10];
int createTree(int ml, int mr, int pl, int pr)
{
    int np = p++, i;
    node[np].val = postStr[pr];
    if(ml > mr || pl > pr)
        return 0;
    for(i = ml; i <= mr; ++i)
    {
        if(midStr[i] == postStr[pr])
            break;
    }
    node[np].left = createTree(ml, i-1, pl, i-ml+pl-1);
    node[np].right = createTree(i+1, mr, i-ml+pl, pr-1);
    return np;
}
void preOrder(int r)
{
    if(r != 0)
    {
        cout<<node[r].val;
        preOrder(node[r].left);
        preOrder(node[r].right);
    }
}

int main()
{
    cin>>midStr>>postStr;
    int l = strlen(midStr);
    int root = createTree(0, l - 1, 0, l - 1);
    preOrder(root);
    return 0;
}
